Made sure all the error cases involving jpeg or png load/saves clean
authorManish Singh <yosh@gimp.org>
Sun, 20 Jan 2002 04:52:47 +0000 (04:52 +0000)
committerManish Singh <yosh@src.gnome.org>
Sun, 20 Jan 2002 04:52:47 +0000 (04:52 +0000)
Sat Jan 19 20:49:20 2002  Manish Singh  <yosh@gimp.org>

        * io-jpeg.c, io-png.c: Made sure all the error cases involving
        jpeg or png load/saves clean themselves up properly. Marked some
        variables needed for cleanup volatile so they aren't clobbered by
        setjmp.

gdk-pixbuf/ChangeLog
gdk-pixbuf/io-jpeg.c
gdk-pixbuf/io-png.c

index b548f247abc01f3bee5e181a814f7dbb31126c3c..3853731e6b44f5c830fcf435acf39f07dedc8ef4 100644 (file)
@@ -1,3 +1,10 @@
+Sat Jan 19 20:49:20 2002  Manish Singh  <yosh@gimp.org>
+
+       * io-jpeg.c, io-png.c: Made sure all the error cases involving
+       jpeg or png load/saves clean themselves up properly. Marked some
+       variables needed for cleanup volatile so they aren't clobbered by
+       setjmp.
+
 Fri Jan 11 18:05:07 2002  Owen Taylor  <otaylor@redhat.com>
 
        * pixops/pixops.c: Fix integer overflow for the values
index 0cc66cdbf78845661c45627afd0a99391cb512e0..87bfbe185c45afe12cd026253b7b6eedd0634e2d 100644 (file)
@@ -182,7 +182,7 @@ static GdkPixbuf *
 gdk_pixbuf__jpeg_image_load (FILE *f, GError **error)
 {
        gint w, h, i;
-       guchar *pixels = NULL;
+       guchar * volatile pixels = NULL;
        guchar *dptr;
        guchar *lines[4]; /* Used to expand rows, via rec_outbuf_height, 
                            * from the header file: 
@@ -203,7 +203,7 @@ gdk_pixbuf__jpeg_image_load (FILE *f, GError **error)
        if (sigsetjmp (jerr.setjmp_buffer, 1)) {
                /* Whoops there was a jpeg error */
                if (pixels)
-                       free (pixels);
+                       g_free (pixels);
 
                jpeg_destroy_decompress (&cinfo);
                return NULL;
@@ -719,7 +719,7 @@ gdk_pixbuf__jpeg_image_save (FILE          *f,
        cinfo.err = jpeg_std_error (&(jerr.pub));
        if (sigsetjmp (jerr.setjmp_buffer, 1)) {
                jpeg_destroy_compress (&cinfo);
-               free (buf);
+               g_free (buf);
                return FALSE;
        }
 
@@ -754,7 +754,7 @@ gdk_pixbuf__jpeg_image_save (FILE          *f,
        
        /* finish off */
        jpeg_finish_compress (&cinfo);   
-       free (buf);
+       g_free (buf);
        return TRUE;
 }
 
index d4cd962289153b91358f28181546415d1349fdc9..aedd0be18bdce81b9537feb333d6d8001b42d858 100644 (file)
@@ -211,8 +211,8 @@ gdk_pixbuf__png_image_load (FILE *f, GError **error)
         gboolean failed = FALSE;
        gint i, ctype, bpp;
        png_uint_32 w, h;
-       png_bytepp rows;
-       guchar *pixels;
+       png_bytepp volatile rows = NULL;
+       guchar * volatile pixels = NULL;
         gint    num_texts;
         gchar **options = NULL;
 
@@ -236,6 +236,12 @@ gdk_pixbuf__png_image_load (FILE *f, GError **error)
        }
 
        if (setjmp (png_ptr->jmpbuf)) {
+               if (rows)
+                       g_free (rows);
+
+               if (pixels)
+                       g_free (pixels);
+
                png_destroy_read_struct (&png_ptr, &info_ptr, &end_info);
                return NULL;
        }
@@ -728,6 +734,7 @@ gdk_pixbuf__png_image_save (FILE          *f,
        int has_alpha;
        int bpc;
        int num_keys;
+       gboolean success = TRUE;
 
        num_keys = 0;
 
@@ -802,12 +809,12 @@ gdk_pixbuf__png_image_save (FILE          *f,
 
        info_ptr = png_create_info_struct (png_ptr);
        if (info_ptr == NULL) {
-               png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
-               return FALSE;
+              success = FALSE;
+              goto cleanup;
        }
        if (setjmp (png_ptr->jmpbuf)) {
-               png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
-               return FALSE;
+              success = FALSE;
+              goto cleanup;
        }
 
        if (num_keys > 0) {
@@ -842,6 +849,8 @@ gdk_pixbuf__png_image_save (FILE          *f,
        }
 
        png_write_end (png_ptr, info_ptr);
+
+cleanup:
        png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
 
        if (num_keys > 0) {
@@ -850,7 +859,7 @@ gdk_pixbuf__png_image_save (FILE          *f,
                g_free (text_ptr);
        }
 
-       return TRUE;
+       return success;
 }